package com.ruoyi.waterPrice.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.business.waterPrice.WiOrgfeeY;
import com.ruoyi.waterPrice.service.IWiOrgfeeYService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 水管机构水费核算Controller
 *
 * @author ps
 * @date 2023-02-16
 */
@RestController
@RequestMapping("/WiOrgfeeY")
public class WiOrgfeeYController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(WiOrgfeeYController.class);

    @Autowired
    private IWiOrgfeeYService wiOrgfeeYService;

    /**
     * 查询收缴方式
     */
    @GetMapping("/getFeeKind")
    public AjaxResult getFeeKind(String year) {
        String feeFind = wiOrgfeeYService.getFeeKind(year);
        HashMap<String, String> res = new HashMap<>();
        res.put("feeKind", feeFind);
        return AjaxResult.success(res);
    }

    /**
     * 水费核算 -- 根据收费模式，计算各级机构及用水户的水费。
     * 根据机构 核算该机构 农户水费
     * 同时落机构表 农户表
     */
    @GetMapping("/caleFee")
    public AjaxResult caleFee(String year, String orgCd) {
        log.info("水费核算 入参：" + year + "=" + orgCd);
        HashMap<String, Object> resMap = wiOrgfeeYService.caleFee(year, orgCd);
        if ((Boolean) resMap.get("status")) {
            return AjaxResult.success(resMap.get("msg"));
        } else {
            return AjaxResult.error((String) resMap.get("msg"));
        }
    }


    /**
     * 查询水管机构水费核算列表
     */
    @RequiresPermissions("waterPrice:WiOrgfeeY:list")
    @GetMapping("/list")
    public TableDataInfo list(WiOrgfeeY wiOrgfeeY) {
        startPage();
        List<WiOrgfeeY> list = wiOrgfeeYService.selectWiOrgfeeYList(wiOrgfeeY);
        return getDataTable(list);
    }

    /**
     * 导出水管机构水费核算列表
     */
    @RequiresPermissions("waterPrice:WiOrgfeeY:export")
    @Log(title = "水管机构水费核算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WiOrgfeeY wiOrgfeeY) {
        List<WiOrgfeeY> list = wiOrgfeeYService.selectWiOrgfeeYList(wiOrgfeeY);
        ExcelUtil<WiOrgfeeY> util = new ExcelUtil<WiOrgfeeY>(WiOrgfeeY.class);
        util.exportExcel(response, list, "水管机构水费核算数据");
    }

    /**
     * 获取水管机构水费核算详细信息
     */
    @RequiresPermissions("waterPrice:WiOrgfeeY:query")
    @GetMapping(value = "/{feeYr}/{orgCd}")
    public AjaxResult getInfo(@PathVariable("feeYr") String feeYr, @PathVariable("orgCd") String orgCd) {
        return success(wiOrgfeeYService.selectWiOrgfeeYByFeeYrAndOrgCd(feeYr, orgCd));
    }

    /**
     * 新增水管机构水费核算
     */
    @RequiresPermissions("waterPrice:WiOrgfeeY:add")
    @Log(title = "水管机构水费核算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WiOrgfeeY wiOrgfeeY) {
        return toAjax(wiOrgfeeYService.insertWiOrgfeeY(wiOrgfeeY));
    }

    /**
     * 修改水管机构水费核算
     */
    @RequiresPermissions("waterPrice:WiOrgfeeY:edit")
    @Log(title = "水管机构水费核算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WiOrgfeeY wiOrgfeeY) {
        return toAjax(wiOrgfeeYService.updateWiOrgfeeY(wiOrgfeeY));
    }

    /**
     * 删除水管机构水费核算
     */
    @RequiresPermissions("waterPrice:WiOrgfeeY:remove")
    @Log(title = "水管机构水费核算", businessType = BusinessType.DELETE)
    @DeleteMapping("/{feeYrs}")
    public AjaxResult remove(@PathVariable String[] feeYrs) {
        return toAjax(wiOrgfeeYService.deleteWiOrgfeeYByFeeYrs(feeYrs));
    }
}
